#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

static void vector_display(const vector<int>& v) {
    for (int i = v.size() - 1; i >= 0; --i)
        cout << v[i];
}

static vector<int> vector_times(const vector<int>& v, int a = 20) {
    vector<int> r;
    int c = 0;
    for (auto e : v) {
        c += a * e;
        r.push_back(c % 10);
        c /= 10;
    }
    while (c) {
        r.push_back(c % 10);
        c /= 10;
    }
    return r;
}

// a < b, return 1
// a = b, return 0
// a > b, return -1
static int vector_compare(const vector<int>& a, const vector<int>& b) {
    if (a.size() < b.size())
        return 1;
    if (a.size() > b.size())
        return -1;
    for (int i = a.size() - 1; i >= 0; --i) {
        if (a[i] < b[i])
            return 1;
        if (a[i] > b[i])
            return -1;
    }
    return 0;
}

static void vector_subtraction(vector<int>& a, vector<int>& b) {
    for (int i = 0; i < b.size(); ++i) {
        if (a[i] < 0) {
            a[i] += 10;
            a[i + 1] -= 1;
        }
        a[i] -= b[i];
        if (a[i] < 0) {
            a[i] += 10;
            a[i + 1] -= 1;
        }
    }
    while (a.back() == 0)
        a.pop_back();
}

static int square_root_digital_expansion_sum(int n) {
    vector<int> a {static_cast<int>(sqrt(n))};
    vector<int> b {n - a[0] * a[0]};
    if (b[0] > 9) {
        b.push_back(b[0] / 10);
        b[0] = b[0] % 10;
    }
    while (a.size() < 100) {
        b.insert(b.begin(), 2, 0);
        auto p = vector_times(a, 20);
        int d = 9;
        for (d = 9; d > 0; --d) {
            p[0] = d;
            auto t = vector_times(p, d);
            if (vector_compare(t, b) == 1) {
                vector_subtraction(b, t);
                a.insert(a.begin(), 1, d);
                break;
            }
        }
        if (d == 0)
            a.insert(a.begin(), 1, 0);
    }
    vector_display(a);
    cout << ": " << n << endl;
    return accumulate(a.begin(), a.end(), 0);
}

int main() {
#if 0
    cout << square_root_digital_expansion_sum(47) << endl;
#else 
    int ans = 0;
    for (int i = 2; i < 100; ++i) {
        int r = sqrt(i) + .5;
        if (r * r != i)
            ans += square_root_digital_expansion_sum(i);
    }
    cout << ans << endl;
#endif 
}